package com.seednia.module.core.tagging.dto;

import java.util.Date;

import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.seednia.foundation.framework.dto.AbstractRecord;
import com.seednia.foundation.framework.dto.Constants;
import com.seednia.foundation.framework.dto.ICriteria;

/**
 * Criteria class for Tagging
 * 
 * @author Young Suk Ahn
 *
 */
@XmlRootElement(name = "TaggingCriteria", 
namespace = "http://seednia.com/core/1.0")
@XmlType(name = "TaggingCriteria")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class TaggingCriteria extends TaggingDto implements ICriteria {


	/**
	 * 
	 */
	private static final long serialVersionUID = -1476717801752339264L;
	
	private ITaggable taggable = null;

	public TaggingCriteria(){
		this.setSid(Constants.SID_ANY);
	}
	public TaggingCriteria(ITaggable taggable, TaggingDto taggingDto){
		this.setSid(taggingDto.getSid());
		this.taggable = taggable;
		this.setTargetType(taggingDto.getTargetType());
		this.setTargetSid(taggable.getSid());
	}
	public TaggingCriteria(ITaggable taggable, String tagType){
		this.setSid(Constants.SID_ANY);
		this.taggable = taggable;
		this.setTargetType(tagType);
		this.setTargetSid(taggable.getSid());
	}
	
	@Override
	public Date getCreatedBefore() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Date getCreatedAfter() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public void setSearchText(String value)
	{
		throw new UnsupportedOperationException();
	}
		
	@Transient
	public ITaggable getTaggable()
	{
		return this.taggable;
	}
	
	// This is used by Hibernate
	public Class<?> getTaggingDtoClass()
	{
		return taggable.getTaggingDtoClass(this.getTargetType());
	}

	/**
	 * To create object from JSONP string
	 * Used by the REST framework when sending this object as parameter
	 * @param jsonStr
	 * @return
	 */
	public static TaggingCriteria fromString(String jsonStr) {
		TaggingCriteria retval = (TaggingCriteria) AbstractRecord.fromString(TaggingCriteria.class, jsonStr);
		return retval;
	}
}
